import { h, reactive, ref } from "vue"

import FormBuilder from "../components/FormBuilder.vue"

export const useFormBuilder = props => {
  const formRef = ref()
  const Component = (_, { slots }) => {
    return h(FormBuilder, { ...reactive(props), ref: formRef }, slots)
  }

  return {
    FormBuilder: Component,
    validate() {
      return formRef.value?.validate()
    },
  }
}
